using System;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Runtime.Remoting;

namespace Library.OrmEnterpriseEntity {
	internal class BaseDbDataReader : DbDataReader {
		private readonly BaseService _baseService;
		private readonly DbDataReader _dbDataReader;

		internal BaseDbDataReader(DbDataReader dbDataReader, BaseService baseService) {
			_dbDataReader = dbDataReader;
			_baseService = baseService;
			_baseService.SelectFetchRow = 0;
		}

		public override int Depth {
			get { return _dbDataReader.Depth; }
		}

		public override int FieldCount {
			get { return _dbDataReader.FieldCount; }
		}

		public override bool HasRows {
			get { return _dbDataReader.HasRows; }
		}

		public override bool IsClosed {
			get { return _dbDataReader.HasRows; }
		}

		public override int RecordsAffected {
			get { return _dbDataReader.RecordsAffected; }
		}

		public override object this[string name] {
			get { return _dbDataReader[name]; }
		}

		public override object this[int ordinal] {
			get { return _dbDataReader[ordinal]; }
		}

		public override int VisibleFieldCount {
			get { return _dbDataReader.VisibleFieldCount; }
		}

		public override void Close() {
			_dbDataReader.Close();
			_baseService.Dispose();
		}

		public override bool GetBoolean(int ordinal) {
			return _dbDataReader.GetBoolean(ordinal);
		}

		public override byte GetByte(int ordinal) {
			return _dbDataReader.GetByte(ordinal);
		}

		public override long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length) {
			return _dbDataReader.GetBytes(ordinal, dataOffset, buffer, bufferOffset, length);
		}

		public override char GetChar(int ordinal) {
			return _dbDataReader.GetChar(ordinal);
		}

		public override long GetChars(int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length) {
			return _dbDataReader.GetChars(ordinal, dataOffset, buffer, bufferOffset, length);
		}

		public override string GetDataTypeName(int ordinal) {
			return _dbDataReader.GetDataTypeName(ordinal);
		}

		public override DateTime GetDateTime(int ordinal) {
			return _dbDataReader.GetDateTime(ordinal);
		}

		public override decimal GetDecimal(int ordinal) {
			return _dbDataReader.GetDecimal(ordinal);
		}

		public override double GetDouble(int ordinal) {
			return _dbDataReader.GetDouble(ordinal);
		}

		public override IEnumerator GetEnumerator() {
			return _dbDataReader.GetEnumerator();
		}

		public override Type GetFieldType(int ordinal) {
			return _dbDataReader.GetFieldType(ordinal);
		}

		public override float GetFloat(int ordinal) {
			return _dbDataReader.GetFloat(ordinal);
		}

		public override Guid GetGuid(int ordinal) {
			return _dbDataReader.GetGuid(ordinal);
		}

		public override short GetInt16(int ordinal) {
			return _dbDataReader.GetInt16(ordinal);
		}

		public override int GetInt32(int ordinal) {
			return _dbDataReader.GetInt32(ordinal);
		}

		public override long GetInt64(int ordinal) {
			return _dbDataReader.GetInt64(ordinal);
		}

		public override string GetName(int ordinal) {
			return _dbDataReader.GetName(ordinal);
		}

		public override int GetOrdinal(string name) {
			return _dbDataReader.GetOrdinal(name);
		}

		public override DataTable GetSchemaTable() {
			return _dbDataReader.GetSchemaTable();
		}

		public override string GetString(int ordinal) {
			return _dbDataReader.GetString(ordinal);
		}

		public override object GetValue(int ordinal) {
			return _dbDataReader.GetValue(ordinal);
		}

		public override int GetValues(object[] values) {
			return _dbDataReader.GetValues(values);
		}

		public override bool IsDBNull(int ordinal) {
			return _dbDataReader.IsDBNull(ordinal);
		}

		public override bool NextResult() {
			bool result = _dbDataReader.NextResult();
			if (result) _baseService.SelectFetchRow = 0;
			return result;
		}

		public override bool Read() {
			bool result = _dbDataReader.Read();
			if (result) _baseService.SelectFetchRow++;
			return result;
		}

		public override ObjRef CreateObjRef(Type requestedType) {
			return _dbDataReader.CreateObjRef(requestedType);
		}

		public override bool Equals(object obj) {
			return _dbDataReader.Equals(obj);
		}

		public override int GetHashCode() {
			return _dbDataReader.GetHashCode();
		}

		public override Type GetProviderSpecificFieldType(int ordinal) {
			return _dbDataReader.GetProviderSpecificFieldType(ordinal);
		}

		public override object GetProviderSpecificValue(int ordinal) {
			return _dbDataReader.GetProviderSpecificValue(ordinal);
		}

		public override int GetProviderSpecificValues(object[] values) {
			return _dbDataReader.GetProviderSpecificValues(values);
		}

		public override object InitializeLifetimeService() {
			return _dbDataReader.InitializeLifetimeService();
		}

		public override string ToString() {
			return _dbDataReader.ToString();
		}
	}
}